
var
	a:array[0 .. 7] of integer;
	b:array[0..7] of boolean;
	max:integer;

procedure search(n:integer);
var
	i:integer;
begin
	if(n=max)then
	begin
		for i:=0 to max-1 do
		begin
			write(a[i]+1,' ');
		end;
		writeln;
	end
	else
	for i:=0 to max-1 do
	begin
		if(b[i]=false)then
		begin
			b[i]:=true;
			a[n]:=i;
			search(n+1);
			b[i]:=false;
		end;
	end;
end;

begin
	readln(max);
	search(0);
end.
